//导入article模块
const article = require('../../model/article');
const path = require('path');
//导入第三方模块formidable
const formidable = require('formidable');
module.exports = (req, res) => {
    //创建formidable解析对象
    let form = new formidable.IncomingForm();
    form.uploadDir = path.join(__dirname, '../', '../', 'public', 'uploads');
    form.keepExtensions = true;
    form.parse(req, async(err, fields, files) => {
        //fields:存储表单信息
        //files:存储二进制文件信息
        // res.send(fields)
        let id = req.query.id;
        // // res.send(id)
        // res.send(files)
        let data = {
            title: fields.title,
            author: fields.author,
            publishDate: fields.publishDate,
            cover: files.cover.path.split('public')[1],
            content: fields.content
        }
        await article.updateOne({ _id: id }, data);
        res.redirect('/admin/article');
        // res.send(fields.author)
    })
}